﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace XclusiveService.Models
{
    public class OrderRepository : IOrderRepository
    {
        public OrderRepository()
        {

        }

        public IEnumerable<Order> GetAll()
        {
            return DatabaseManager.GetAllOrder().Cast<Order>();
        }

        public Order GetById(int id)
        {
            return DatabaseManager.GetOrderById(id);
        }

        public Order Add(Order item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            if (DatabaseManager.InsertOrder(item) == 0)
            {
                return null;
            }
            else
            {
                return item;
            }
        }

        public void Remove(int id)
        {
            DatabaseManager.DeleteOrder(id);
        }

        public bool Update(Order item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            if (DatabaseManager.UpdateOrder(item) == 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }
}